import { Discount, GoodPrice, HighScore, HotRecommend, Longfor, Plus } from "@/http/modules/home";

const { createSlice, createAsyncThunk } = require("@reduxjs/toolkit");

export const getGoodPrice = createAsyncThunk("HomeGoodPrice",async ()=>{
    const res = await GoodPrice();
    return res
})

export const getHighScore = createAsyncThunk("HighScore",async ()=>{
    const res = await HighScore();
    return res
})

export const getDiscountInfo = createAsyncThunk('DiscountInfo',async ()=>{
    const res = await Discount();
    return res
})

export const getHotrecommend = createAsyncThunk('Hotrecommend',async ()=>{
    const res = await HotRecommend();
    return res
})

export const getLongfor = createAsyncThunk("Longfor",async ()=>{
    const res = await Longfor();
    return res
})

export const getPlus = createAsyncThunk("Plus",async ()=>{
    const res = await Plus();
    return res
})

const homeSlice = createSlice({
    name:"home",
    initialState:{
        homeGoodPriceInfo:{},
        HighScoreInfo:{},
        DiscountInfo:{},
        HotrecommendInfo:{},
        LongforInfo:{},
        PlusInfo:{}
    },
    reducers:{
    },
    extraReducers:{
        [getGoodPrice.fulfilled](state,{payload}){
            state.homeGoodPriceInfo = payload;
        },
        [getHighScore.fulfilled](state,{payload}){
            state.HighScoreInfo = payload
        },
        [getDiscountInfo.fulfilled](state,{payload}){
            state.DiscountInfo = payload
        },
        [getHotrecommend.fulfilled](state,{payload}){
            state.HotrecommendInfo = payload
        },
        [getLongfor.fulfilled](state,{payload}){
            state.LongforInfo = payload
        },
        [getPlus.fulfilled](state,{payload}){
            state.PlusInfo = payload
        }
    }
})
 
export default homeSlice.reducer